﻿
@using TS2015.Models;
@{
    TS2015Context db = new TS2015Context();
    List<TS2015.Models.TbChucNang> menuList = db.TbChucNangs.ToList();
}
<ul class="nav mb20">

    @foreach (var mp in menuList.Where(p => p.MaCNCha == 0))
    {

        <li>
            <a href="javascript:;">
                <i class="toggle-accordion glyphicon glyphicon-chevron-down"></i>
                <i class="glyphicon glyphicon-cog"></i>
                <span>@mp.TenCN</span>
            </a>
            @if (menuList.Count(p => p.MaCNCha == mp.MaCN) > 0)
            {
                @:<ul class="sub-menu">
            }

            @RenderMenuItem(menuList, mp)

            @if (menuList.Count(p => p.MaCNCha == mp.MaCN) > 0)
            {
                @:</ul>
            }

        </li>
    }
</ul>


@helper RenderMenuItem(List<TS2015.Models.TbChucNang> menuList, TS2015.Models.TbChucNang mi)
{
    foreach (var cp in menuList.Where(p => p.MaCNCha == mi.MaCN))
    {


        @:<li>
            <span>@cp.TenCN</span>

        if (menuList.Count(p => p.MaCNCha == cp.MaCN) > 0)
        {
            @:<ul>
        }

        @RenderMenuItem(menuList, cp)
        if (menuList.Count(p => p.MaCNCha == cp.MaCN) > 0)
        {
            @:</ul>
      }
        else
        {
            @:</li>
      }
    }
}